#include<stdio.h>
#include<stdlib.h>
struct node
{
    int data;
    struct node *next;
};
struct node* create_la(struct node *heada,int m)
{
    struct node *s,*r;
    int x;
    while(m--)
    {
        scanf("%d",&x);
        s=(struct node*)malloc(sizeof(struct node));
        s->data=x;
        if(heada==NULL)heada=s;
        else r->next=s;
        r=s;
    }
    if(r!=NULL) r->next=NULL;
    return heada;
}

void del(struct node *L){
	if (L!=NULL) {
		del(L->next);
		free(L);
	}
}


struct node* create_lb(struct node *headb,int n)
{
    struct node *s,*r;
    int x;
    while(n--)
    {
        scanf("%d",&x);
        s=(struct node*)malloc(sizeof(struct node));
        s->data=x;
        if(headb==NULL)headb=s;
        else r->next=s;
        r=s;
    }
    if(r!=NULL) r->next=NULL;
    return headb;
}

int main()
{
    int m,n;
    struct node *heada=NULL,*headb=NULL,*headc=NULL,*head=NULL;
    while(scanf("%d",&m)!=EOF)
    {
        heada=create_la(heada,m);
        scanf("%d",&n);
        headb=create_lb(headb,n);
       
        for(;heada!=NULL&&headb!=NULL;headc->next)
        {
            headc=(struct node*)malloc(sizeof(struct node));
            head=headc;
            if(heada->data<=headb->data)
            {
                headc->data=heada->data;
                printf("%d ",headc->data);
                heada=heada->next;
            }
            else
            {
                headc->data=headb->data;
                printf("%d ",headc->data);
                headb=headb->next;
            }
        }
        if(heada==NULL)
        {

            for(;headb!=NULL;headb=headb->next,headc=headc->next)
                { headc=(struct node*)malloc(sizeof(struct node));
                headc->data=headb->data;
                printf("%d ",headc->data);
                }
        }
        else
        {
            for(;heada!=NULL;heada=heada->next,headc=headc->next)
                { headc=(struct node*)malloc(sizeof(struct node));
                headc->data=heada->data;
                printf("%d ",headc->data);
                }
        }
        //headc->next=head;
        //del(headc);
        //headc->next=head;
        //printf("\n");
       /* headc=head;
        for(;headc->next!=head;headc=headc->next)
        {
            printf("%d ",headc->data);
        }*/

  
    } 
    return 0;
}

  /*
        headc->next=head;
        headc=head->next;
        for(headc;headc->next!=head;headc=headc->next)
        {
            printf("%d ",headc->data);
        }
*/



 
    /*for(;heada!=NULL;heada=heada->next)
        printf("%d ",heada->data); 
    for(;headb!=NULL;headb=headb->next)
        printf("%d ",headb->data); 
    }*/